package parser;

import collector.Range;

public class TextLine {

    private final StringBuffer text = new StringBuffer();

    private int sTokenIndex = 0;
    private int eTokenIndex = 0;

    public void addToken(int tokenIndex) {
        if (sTokenIndex == 0) {
            sTokenIndex = tokenIndex;
        }

        if (sTokenIndex > tokenIndex) {
            sTokenIndex = tokenIndex;
        }

        if (eTokenIndex < tokenIndex) {
            eTokenIndex = tokenIndex;
        }
    }

    public String getString() {
        return text.toString().intern();
    }

    public void addString(String value) {
        text.append(value);
    }

    public String toString() {
        StringBuffer sb = new StringBuffer();
        sb.append(getString()).append("\t:");
        return sb.toString().intern();
    }

    public Range getTokenRange() {
        return new Range(sTokenIndex, eTokenIndex);
    }
}
